<?php
/*
* Author: Nguyen Hai Nam
* Module: Admin
* Desc  : Introduce pick.vn and sidle pic
* Date  : 12/12/2011
*/
class ChangePassModule extends Pick_Core_Module{
    
    public $authentication = 1;
    
    function ChangePassModule(){
        
        parent::Pick_Core_Module();
        $this->theme = "admin";
        # Languages
        $languages = new Pick_Core_Languages();
        $objectLanguages = "";
        $objectLanguages = $languages->getObjects(1, 'status = 1', array('position'=>'ASC'), '');
        if($objectLanguages){
            $objectLanguages = $objectLanguages['data'];    
        }#endif
        $this->template->assign("objectLanguages", $objectLanguages);
        
        // Get Path for this module
        $this->template->assign('arrayParentPath', $this->getArrayParentPath());
    }
    public function getContent(){
        $act = $this->request->element('act', 'index');
        $this->template->assign('act', $act);
        switch($act){
            case 'changepass':{
               return $this->forgotAction();
            }break;
            case 'profile':{
                return $this->profileAction();
            }
            default:{
            	return $this->indexAction();
            }
        }
    }
    public function indexAction(){
        $error ='';
        if($this->request->isPost()){
            $oldpass = trim($this->request->element("oldpass"));
            $newpass = trim($this->request->element("newpass"));
            $renewpass = trim($this->request->element("renewpass"));
            $users = new Pick_Core_User();
            $userinfo = $users->getInfoCurrentUser();
            if(!empty($oldpass) && (md5($oldpass) == $userinfo->getField('password'))) {
                if(!empty($newpass) && !empty($renewpass) && ($newpass == $renewpass)){
                    $users->updatePassword($newpass);
                    $error .= l('Your passwork was be updated successfully. Please logout and login again to check it. Thanks');
                }else{
                    $error .= l('The newpassword and renewpassword are not match. Please check it again.');
                }
            }else{
                $error .= l('This password is not valid. Please try more again.');
            }
            $this->template->assign('oldpass',$oldpass);
            $this->template->assign('newpass',$newpass);
            $this->template->assign('renewpass',$renewpass);
        }
        $this->template->assign('error',$error);
    }
    public function profileAction(){

    }
}